package com.itheima.demo07;

/**
 * @author Zhang_Han
 * @version 1.0
 * @date 2020/7/14 13:52
 */
public class Demo_002 {
    public static void main(String[] args) {

        //多线程的可见性问题:
        //可以通过synchronized解决 ;
        //也可以使用volatile来解决;
        new Thread(new Runnable() {
            @Override
            public void run() {
                //小皮同学;
                synchronized (Maney.lock) {
                    try {
                        Thread.sleep(200);
                        Maney.maney = 90000;
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                //小路同学 ;
                synchronized (Maney.lock) {
                    while (Maney.maney == 100000) {
                    }
                    System.out.println("结婚基金已经不是十万元了;");
                }
            }
        }).start();
    }
}

class Maney {
    public static int maney = 100000;
    public static final Object lock = new Object();
}
